/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-04-22
 * Time: 23:52
 */
class Node{
    public int value;//定义这个节点的值
    public Node next;//定义节点
    public Node(int value) {//初始化节点
        this.value = value;
    }
    public void printCommonPart(Node head1,Node head2) {
        System.out.println("PrintCommon");
        Node cur1 = head1;
        Node cur2 = head2;
        while(cur1!=null&&cur2!=null) {
            if(cur1.value>cur2.value) {
                cur2 = cur2.next;
            }else if(cur1.value<cur2.value) {
                cur1=cur1.next;
            }else {
                System.out.print(cur1.value+"->");
                cur1 =cur1.next;
                cur2=cur2.next;
            }
        }
        System.out.println("null");
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Node node1 = new Node(1);
        Node node2 = new Node(2);
        Node node3 = new Node (3);
        Node node4 = new Node (2);
        Node node5 = new Node (1);
        Node node6 = new Node (3);
        Node node7 = new Node (3);
        Node node8 = new Node (5);
        //1->2->3->2
        //1->3->3->5
        node1.next =node2;
        node2.next =node3;
        node3.next =node4;
        node4.next =null;
        node5.next=node6;
        node6.next =node7;
        node7.next =node8;
        node8.next =null;
        node1.printCommonPart(node1,node5);
    }
}
